package io.gitee.geminidev.bot;

import io.gitee.geminidev.bot.domain.MessageResponse;
import io.gitee.geminidev.bot.type.Code;
import io.gitee.geminidev.bot.type.IntentType;

/**
 * @Author Gemini
 * @Date 2023/4/2 22:14
 * @description: 使用示例
 */
public class Main {
    public static void main(String[] args) {
        Bot bot = BotFactory.createBot(
                "102050566", // 申请机器人时获取到的机器人 BotAppID
                "DrjsNmr9hBK9T0dK3P9LjlwRWPSmdKmT", // 申请机器人时获取到的机器人令牌
                false // 沙箱支持，可选，默认false
        );
        bot.intents(IntentType.GUILDS,
                        IntentType.GUILD_MEMBERS,
                        IntentType.GUILD_MESSAGE_REACTIONS,
                        IntentType.OPEN_FORUMS_EVENT,
                        IntentType.AUDIO_OR_LIVE_CHANNEL_MEMBER,
                        IntentType.INTERACTION,
                        IntentType.AUDIO_ACTION,
                        IntentType.GUILD_MESSAGES)
                .onReady(message -> Code.CONTINUE)
                .onGuildCreate(message -> {
                    System.out.println(message.getDescription());
                    return Code.CONTINUE;
                })
                .onChannelCreate(message -> {
                    System.out.println(message.getGuild_id());
                    return Code.CONTINUE;
                })
                .onMessageCreate(message -> {
                    MessageResponse content = MessageResponse.create().messageReference(message.getId())
                            .content(String.format("收到频道消息: %s", message.getContent()));
                    bot.messageApi().sendMessage(message.getChannelId(), content);
                    return Code.CONTINUE;
                })
                .onAtMessageCreate(message -> {
                    MessageResponse content = MessageResponse.create().messageReference(message.getId())
                            .content(String.format("收到频道At消息: %s", message.getContent()));
                    bot.messageApi().sendMessage(message.getChannelId(), content);
                    return Code.CONTINUE;
                })
                .start();
    }
}